﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Collections.Generic;
using Yipusoft.Common.Model;
using Yipusoft.Common.BLL;
using Yipusoft.Account.BLL;
using Yipusoft.Account.Model;
using Yipusoft.SoldierArchives.BLL;
using System.Drawing;
using Yipusoft.SoldierArchives.Model;

public partial class BasicBase_SoldierArchive_SoldierCustom : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
        if (!Page.IsPostBack)
        {        
            BindCustom();  

        }

    }

    public void ListPageContral1_PageSizeChange(int pageSize, int PageIndex)
    {
        this.GvwCustom.PageIndex = PageIndex;
        BindCustom();
    }

    private void BindCustom()
    {
        List<ConditionInfo> info = ConditionValue.GetConditionBySetUserID(User.Identity.Name);
        if (info == null)
            return;

        this.ListPageContral1.ItemCount = info.Count;
        this.GvwCustom.DataSource = info;
        this.GvwCustom.DataBind();
    }
    private List<DepartmentInfo> GetDepartmentList(string departmentID, string permissionLevel, string permissionUnit)
    {
        List<DepartmentInfo> departmentList = new List<DepartmentInfo>();
        if (Yipusoft.Account.BLL.User.HasPermission(Context.User.Identity.Name, permissionLevel) || Yipusoft.Account.BLL.User.HasPermission(Context.User.Identity.Name, permissionUnit))
            departmentList = Department.GetList("DepartmentID='" + departmentID.Substring(0, 4) + "000'");
        return departmentList;
    }



   

    protected void imbDelete_Command(object sender, CommandEventArgs e)
    {
        if (ConditionValue.DeleteCondition(Convert.ToInt32(e.CommandArgument)))
        {
            BindCustom();
        }
    }


    protected void GvwCustom_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = (GvwCustom.PageIndex * GvwCustom.PageSize + e.Row.RowIndex + 1).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
    
        }

    }
    protected void lbtnselect_Command(object sender, CommandEventArgs e)
    {
        ConditionInfo conditionInfo = ConditionValue.GetConditionByID(Convert.ToInt32(e.CommandArgument));
        if (Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID == conditionInfo.DepartmentID)
        {
            if (Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, conditionInfo.Permission))
            {
                lblStrName.Text = conditionInfo.Description;               
                Response.Redirect("SoldierSelect.aspx?Uid=" + conditionInfo.ConditionSql);
                //TabContainer1.ActiveTabIndex = 0;            
                //strSql.Value = conditionInfo.ConditionSql;
                //strName.Value = conditionInfo.Description;
                //Label2.Text = conditionInfo.ConditionName;
                //lblDescription.Text = conditionInfo.Description;
                //BindSoldiers(conditionInfo.ConditionSql, 20, 0);
               


                //btn.Command;
            }
            else
                lblStrName.Text = "您的不再有搜索此条件的权限。";

        }
        else
            lblStrName.Text = "由于您的工作调动，请重新制定搜索条件。";
        
    }
}
